/**********************************************************
 * PortalToolsAction.java.java
 * Created by Ashutosh
 * Last modified Date: Sep 18, 2008 10:49:09 AM by Ashutosh
 * Revision: <svn revision #>
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 **********************************************************/

package com.printeverywhere.action;

import org.apache.log4j.Logger;

import com.printeverywhere.delegator.CurrencyServiceDelegator;
import com.printeverywhere.dto.CurrencyConverterConfiguration;

/**
 * The Class PortalToolsAction.
 */
public class PortalToolsAction  extends AdminSystemSetup {

	/** Logger for this class. */
	private static final Logger logger = Logger.getLogger(PortalToolsAction.class);

	private CurrencyConverterConfiguration converterConfiguration;

	private String convertTo;

	private String convertFrom;

	private double amount;

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	public String execute() throws Exception{
		if (logger.isDebugEnabled()) {
			logger.debug("execute() - start"); //$NON-NLS-1$
		}

		converterConfiguration = CurrencyServiceDelegator.getConfigurationList();

		convertTo = converterConfiguration.getDefaultCurrencyConvertTo();
		convertFrom = converterConfiguration.getDefaultCurrencyConvertFrom();
		amount = converterConfiguration.getConvertAmount();

		if (logger.isDebugEnabled()) {
			logger.debug("execute() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	public String updateCurrencyConverterConfiguration() throws Exception{
		if (logger.isDebugEnabled()) {
			logger.debug("updateCurrencyConverterConfiguration() - start"); //$NON-NLS-1$
		}

		converterConfiguration = CurrencyServiceDelegator.getConfigurationList();
		this.converterConfiguration.setDefaultCurrencyConvertFrom(convertFrom);
		this.converterConfiguration.setDefaultCurrencyConvertTo(convertTo);
		this.converterConfiguration.setConvertAmount(amount);
		CurrencyServiceDelegator.updateConfiguration(converterConfiguration);

		if (logger.isDebugEnabled()) {
			logger.debug("updateCurrencyConverterConfiguration() - end"); //$NON-NLS-1$
		}
		addActionMessage("Currency configuration converter successfully");
		return SUCCESS;
	}

	public CurrencyConverterConfiguration getConverterConfiguration() {
		return converterConfiguration;
	}

	public void setConverterConfiguration(
			CurrencyConverterConfiguration converterConfiguration) {
		this.converterConfiguration = converterConfiguration;
	}

	public String getConvertTo() {
		return convertTo;
	}

	public void setConvertTo(String convertTo) {
		this.convertTo = convertTo;
	}

	public String getConvertFrom() {
		return convertFrom;
	}

	public void setConvertFrom(String convertFrom) {
		this.convertFrom = convertFrom;
	}

	public double getAmount() {
		return amount;
	}

	public void setAmount(double amount) {
		this.amount = amount;
	}
}